package com.cqie.practicaltraining.controller;

import com.cqie.practicaltraining.config.result.R;
import com.cqie.practicaltraining.dto.AddEnclosuresDto;
import com.cqie.practicaltraining.dto.EnclosuresDto;
import com.cqie.practicaltraining.service.impl.EnclosuresServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/enclosures")
@Api(value = "圈舍管理")
public class enclosuresController {
    @Autowired
    private EnclosuresServiceImpl enclosuresService;

    @PostMapping("/searchEnclosuresByCondition")
    @ApiOperation(value = "条件获取圈舍信息")
    public R getEnclosuresCondition(@RequestBody @Validated EnclosuresDto enclosuresDto) {
        return enclosuresService.searchEnclosuresByCondition(enclosuresDto);
    }

    @PostMapping("/addEnclosure")
    @ApiOperation(value = "添加圈舍")
    public R addEnclosure(@RequestBody @Validated AddEnclosuresDto enclosuresDto) {
        return enclosuresService.saveEnclosure(enclosuresDto);
    }

    @PutMapping("/updateEnclosure")
    @ApiOperation(value = "修改圈舍")
    public R updateEnclosure(@RequestBody @Validated AddEnclosuresDto enclosuresDto) {
        return enclosuresService.updateEnclosure(enclosuresDto);
    }

    @PutMapping("/updateEnclosureStatus")
    @ApiOperation(value = "修改圈舍状态")
    public R updateEnclosureStatus(@RequestParam Long enclosureId) {
        return enclosuresService.updateEnclosureStatus(enclosureId);
    }
}
